<template>
  <div>
    <!-- 面包屑导航 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item :to="{ path: '/roles'}">权限管理</el-breadcrumb-item>
      <el-breadcrumb-item :to="{ path: '/rights'}">权限列表</el-breadcrumb-item>
    </el-breadcrumb>

    <!-- 卡片视图 -->
    <el-card class="box-card">
      <!-- 列表区 -->
      <el-table :data="rightList" style="width: 100%" border strip fit>
        <el-table-column type="index" label="序号" width="70" />
        <el-table-column prop="id" label="权限Id" width="180" />
        <el-table-column prop="pid" label="父权限Id" width="180" />
        <el-table-column prop="authName" label="菜单名称" width="180" />
        <el-table-column prop="level" label="等级" width="180">
          <template v-slot:default="scope">
            <el-tag v-if="scope.row.level === '0'">一级</el-tag>
            <el-tag v-if="scope.row.level === '1'" type="success">二级</el-tag>
            <el-tag v-if="scope.row.level === '2'" type="warning">三级</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="path" label="路径" width="180" />
        <el-table-column label="操作" width="180" />
      </el-table>
    </el-card>
  </div>
</template>

<script>
export default {
  data() {
    return {
      // 权限列表
      rightList: []
    }
  },
  created() {
    // 获取所有的权限
    this.getRightsList()
  },
  methods: {
    async getRightsList() {
      const { data: res } = await this.$http.get('rights/list')
      // 校验响应状态
      if (res.meta.status !== 200) {
        return this.$message.error('获取权限列表失败！')
      }
      this.rightList = res.data
    }
  }
}
</script>

<style lang="less" scoped>

</style>
